package cn.kgc.cloud.controller;

import cn.kgc.cloud.client.OrderClient;
import cn.kgc.cloud.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/1/4
 * @description
 */
@RestController
@RequestMapping("users")
@Slf4j
public class UserController {


    @Resource
    private OrderClient orderClient;

    @GetMapping("m1")
    public String method1() {

        //  http   http://localhost:8517/orders/m1    feign
        String resp = orderClient.method1();
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m2")
    public String method2() {
        //  http   http://localhost:8517/orders/m2    feign
        String resp = orderClient.method2(10);
        return "invoke userService ok  ---order----> "+resp;
    }


    @GetMapping("m3")
    public String method3() {

        String resp = orderClient.method3(10);
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m4")
    public String method4(String name,Integer number) {

        String resp = orderClient.method4(name,number);
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m5")
    public String method5(String name,Integer number) {

        String resp = orderClient.method5(name,number);
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m6")
    public String method6(String name,Integer number) {

        Order order = new Order(1,name,number);
        String resp = orderClient.method6(order);
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m7")
    public String method7(Integer[] ids) {

        String strIds = Arrays.toString(ids);
        log.info("ids{}",strIds);

        String resp = orderClient.method7(ids);
        return "invoke userService ok  ---order----> "+resp;
    }

    @GetMapping("m8")
    public String method8(Integer id) {

        // json  -> order
        Order order =  orderClient.method8(id);
        return "invoke userService ok  ---order----> "+order;

    }

    @GetMapping("m9")
    public String method9() {

        // json  -> list
        List<Order> orders =  orderClient.method9();
        return "invoke userService ok  ---order----> "+orders;

    }

}
